package m202405.d25;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

/**
 * @@author: 爱做梦的锤子
 * @date: 2024/5/25 15:58
 */
public class Q78 {
    public List<List<Integer>> subsets(int[] nums) {
        List<List<Integer>> res = new ArrayList<>();
        for (int i = 0; i <= nums.length; i++) {
            List<List<Integer>> temp = new ArrayList<>();
            select(nums, 0, i, new LinkedList<>(), temp);
            res.addAll(temp);
        }
        return res;
    }

    private void select(int[] nums, int start, int count, LinkedList<Integer> list, List<List<Integer>> temp) {
        if (count == 0) {
            temp.add(new LinkedList<>(list));
            return;
        }
        for (int i = start; i < nums.length; i++) {
            list.addLast(nums[i]);
            select(nums, i + 1, count - 1, list, temp);
            list.removeLast();
        }
    }
}
